package Server.Poker.FJSSZ;

import java.util.ArrayList;
import java.util.Random;


class tagAnalyseResult {
	int cbFiveCount; //五张数目
	int cbFourCount; // 四张数目
	int cbThreeCount; // 三张数目
	int cbLONGCount; // 两张数目
	int cbSignedCount; // 单张数目
	int cbFiveLogicVolue[] = new int[1]; // 五张列表
	int cbFourLogicVolue[] = new int[1]; // 四张列表
	int cbThreeLogicVolue[] = new int[1]; // 三张列表
	int cbLONGLogicVolue[] = new int[2]; // 两张列表
	int cbSignedLogicVolue[] = new int[5]; // 单张列表
	int cbFiveCardData[] = new int[5]; // 五张列表
	int cbFourCardData[] = new int[5]; // 四张列表
	int cbThreeCardData[] = new int[5]; // 三张列表
	int cbLONGCardData[] = new int[5]; // 两张列表
	int cbSignedCardData[] = new int[5]; // 单张数目

	public void clear() {
		cbFourCount = 0;
		cbThreeCount = 0;
		cbLONGCount = 0;
		cbSignedCount = 0;
		cbFiveCount = 0;
		cbFiveLogicVolue[0] = 0;
		cbFourLogicVolue[0] = 0;
		cbThreeLogicVolue[0] = 0;
		cbLONGLogicVolue[0] = 0;
		cbLONGLogicVolue[1] = 0;
		for (int i = 0; i < 5; i++) {
			cbSignedLogicVolue[i] = 0;
		}
	}
};

class tagAnalyseResult13 {
	int cbFourCount; // 四张数目
	int cbThreeCount; // 三张数目
	int cbLONGCount; // 两张数目
	int cbSignedCount; // 单张数目
	int cbFourLogicVolue[] = new int[13]; // 四张列表
	int cbThreeLogicVolue[] = new int[13]; // 三张列表
	int cbLONGLogicVolue[] = new int[6]; // 两张列表
	int cbSignedLogicVolue[] = new int[13]; // 单张列表
	int cbFourCardData[] = new int[13]; // 四张列表
	int cbThreeCardData[] = new int[13]; // 三张列表
	int cbLONGCardData[] = new int[13]; // 两张列表
	int cbSignedCardData[] = new int[13]; // 单张数目

	public void clear() {
		cbFourCount = 0;
		cbThreeCount = 0;
		cbLONGCount = 0;
		cbSignedCount = 0;
		cbFourLogicVolue[0] = 0;
		cbThreeLogicVolue[0] = 0;
		cbLONGLogicVolue[0] = 0;
		cbLONGLogicVolue[1] = 0;
		for (int i = 0; i < 13; i++) {
			cbSignedLogicVolue[i] = 0;
		}
	}
};

public class GameLogic {
	public static int DRAW = 2; // 和局类型

	// 数值掩码
	public static int LOGIC_MASK_COLOR = (int) 0xF0; // 花色掩码
	public static int LOGIC_MASK_VALUE = 0x0F; // 数值掩码

	public int[] m_byPokerPai;
	public int[] m_byPokerPai5;

	int m_byFetchPos;

	public GameLogic() {
		m_byFetchPos = 0;
		m_byPokerPai = new int[52];
		m_byPokerPai5 = new int[65];
	}

	int random(int iMin, int iMax) {
		Random ra = new Random();
		return ra.nextInt(iMax - iMin) + iMin;
	}

	int m_cbCardListData[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, // 方块
																												// A
																												// -
																												// K
			0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, // 梅花
																							// A
																							// -
																							// K
			0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, // 红桃
																							// A
																							// -
																							// K
			0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, // 黑桃
																							// A
																							// K
	};
	
	int m_cbCardListData5[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, // 方块
			// A
			// -
			// K
            0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, // 梅花
			// A
			// -
			// K
			0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, // 红桃
			// A
			// -
			// K
			0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, // 黑桃
			// A
			0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,																				// -
			// K
};

	// 获取数值
	int GetCardValue(int cbCardData) {
		return (int) (cbCardData & LOGIC_MASK_VALUE);
	}

	// 获取花色
	int GetCardColor(int cbCardData) {
		return (int) (cbCardData & LOGIC_MASK_COLOR);
	}

	// 混乱扑克
	void Ruffle(int in_RandCount) {
		m_byFetchPos = 0;

		System.arraycopy(m_cbCardListData, 0, m_byPokerPai, 0, 65);

		int randseed1 = 0;
		int randseed2 = 0;
		for (int i = 0; i < in_RandCount; i++) {
			Random ra1 = new Random();
			Random ra2 = new Random();
			randseed1 += randseed2;
			randseed2 = ra1.nextInt();
			int randPos1 = randseed1 % 65;
			int randPos2 = randseed2 % 65;

			int by1, by2;
			by1 = m_byPokerPai[randPos1];
			by2 = m_byPokerPai[randPos2];
			m_byPokerPai[randPos1] = by2;
			m_byPokerPai[randPos2] = by1;
		}
	}

	void RandCardList(int cbCardBuffer[], int cbBufferCount) {

		// 混乱准备
		m_byFetchPos = 0;
		System.arraycopy(m_cbCardListData, 0, m_byPokerPai, 0, 52);

		int randseed1 = 0;
		int randseed2 = 0;
		for (int i = 0; i < 1000; i++) {
			randseed1 += randseed2;
			randseed2 = random(1, 10000);
			int randPos1 = randseed1 % 52;
			int randPos2 = randseed2 % 52;
			/*
			 * assert(randPos1 < 52); assert(randPos2 < 52);
			 */
			int by1, by2;
			by1 = m_byPokerPai[randPos1];
			by2 = m_byPokerPai[randPos2];
			m_byPokerPai[randPos1] = by2;
			m_byPokerPai[randPos2] = by1;
		}

		// 混乱扑克
		int bRandCount = 0, bPosition = 0;
		do {
			bPosition = (int) (random(1, 10000) % (52 - m_byFetchPos));
			cbCardBuffer[m_byFetchPos++] = m_byPokerPai[bPosition];
			m_byPokerPai[bPosition] = m_byPokerPai[52 - m_byFetchPos];
		} while (m_byFetchPos < cbBufferCount);

		return;
	}
	
	void RandCardList5(int cbCardBuffer[], int cbBufferCount) {

		// 混乱准备
		m_byFetchPos = 0;
		System.arraycopy(m_cbCardListData5, 0, m_byPokerPai5, 0, 65);

		int randseed1 = 0;
		int randseed2 = 0;
		for (int i = 0; i < 1000; i++) {
			randseed1 += randseed2;
			randseed2 = random(1, 10000);
			int randPos1 = randseed1 % 65;
			int randPos2 = randseed2 % 65;
			/*
			 * assert(randPos1 < 52); assert(randPos2 < 52);
			 */
			int by1, by2;
			by1 = m_byPokerPai5[randPos1];
			by2 = m_byPokerPai5[randPos2];
			m_byPokerPai5[randPos1] = by2;
			m_byPokerPai5[randPos2] = by1;
		}

		// 混乱扑克
		int bRandCount = 0, bPosition = 0;
		do {
			bPosition = (int) (random(1, 10000) % (65 - m_byFetchPos));
			cbCardBuffer[m_byFetchPos++] = m_byPokerPai5[bPosition];
			m_byPokerPai5[bPosition] = m_byPokerPai5[65 - m_byFetchPos];
		} while (m_byFetchPos < cbBufferCount);

		return;
	}

	// 逻辑数值
	int GetCardLogicValue(int cbCardData) {
		// 扑克属性
		int bCardColor = GetCardColor(cbCardData);
		int bCardValue = GetCardValue(cbCardData);

		// 转换数值
		return (int) ((bCardValue == 1) ? (bCardValue + 13) : bCardValue);
	}
	// 逻辑数值
	int GetCardLogicValueBeginSmall(int cbCardData) {
		// 扑克属性
		int bCardColor = GetCardColor(cbCardData);
		int bCardValue = GetCardValue(cbCardData);

		// 转换数值
		return bCardValue;
	}
	// 对比扑克

	// 获取类型
	int GetCardType(int cbCardData[], int cbCardCount) {
		// 数据校验

		int cntZero = 0;
		for(int i=0;i<cbCardCount;i++)
		{
			if(cbCardData[i] == 0)
			{
				cntZero++;
			}
		}
		// 变量定义
		boolean cbSameColor = true, bLineCard = true;
		int cbFirstColor = GetCardColor(cbCardData[0]);
		int cbFirstValue = GetCardLogicValue(cbCardData[0]);

		// 牌形分析
		for (int i = 1; i < cbCardCount; i++) {
			// 数据分析
			if (GetCardColor(cbCardData[i]) != cbFirstColor)
				cbSameColor = false;
			if (cbFirstValue != (GetCardLogicValue(cbCardData[i]) + i))
				bLineCard = false;

			// 结束判断
			if ((cbSameColor == false) && (bLineCard == false))
				break;
		}

		// 最小同花顺
		if ((bLineCard == false) && (cbFirstValue == 14)) {
			int i = 1;
			for (i = 1; i < cbCardCount; i++) {
				int cbLogicValue = GetCardLogicValue(cbCardData[i]);
				if ((cbFirstValue != (cbLogicValue + i + 8)))
					break;
			}
			if (i == cbCardCount)
				bLineCard = true;
		}

		// 皇家同花顺
		if ((cbSameColor == true) && (bLineCard == true) && (GetCardLogicValue(cbCardData[1]) == 13))
			return Constants.CT_KING_TONG_HUA_SHUN;

		// 顺子类型
		if ((cbSameColor == false) && (bLineCard == true))
		{
			if(cbCardData[3] == 0)
			{
				return Constants.CT_SINGLE;
			}else{
				return Constants.CT_SHUN_ZI;
			}
		}

		// 同花类型
		if ((cbSameColor == true) && (bLineCard == false))
		{
			if(cbCardData[3] == 0)
			{
				return Constants.CT_SINGLE;
			}else{
				return Constants.CT_TONG_HUA;
			}
		}

		// 同花顺类型
		if ((cbSameColor == true) && (bLineCard == true))
			return Constants.CT_TONG_HUA_SHUN;

		// 扑克分析
		tagAnalyseResult AnalyseResult = new tagAnalyseResult();
		AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);

		// 类型判断
		if (AnalyseResult.cbFiveCount == 1)
			return Constants.CT_WU_TONG;
		if (AnalyseResult.cbFourCount == 1)
			return Constants.CT_TIE_ZHI;
		if (AnalyseResult.cbLONGCount == 2)
			return Constants.CT_TWO_LONG;
		if ((AnalyseResult.cbLONGCount == 1) && (AnalyseResult.cbThreeCount == 1))
			return Constants.CT_HU_LU;
		if ((AnalyseResult.cbThreeCount == 1) && (AnalyseResult.cbLONGCount == 0))
			return Constants.CT_THREE_TIAO;
		if ((AnalyseResult.cbLONGCount == 1) && (AnalyseResult.cbSignedCount == (3-cntZero)))
			return Constants.CT_ONE_LONG;

		return Constants.CT_SINGLE;
	}
	
	int GetCardTypeFJ(int cbCardData[], int cbCardCount) {
		// 数据校验

		int cntZero = 0;
		for(int i=0;i<cbCardCount;i++)
		{
			if(cbCardData[i] == 0)
			{
				cntZero++;
			}
		}
		// 变量定义
		boolean cbSameColor = true, bLineCard = true;
		int cbFirstColor = GetCardColor(cbCardData[0]);
		int cbFirstValue = GetCardLogicValue(cbCardData[0]);

		// 牌形分析
		for (int i = 1; i < cbCardCount; i++) {
			// 数据分析
			if (GetCardColor(cbCardData[i]) != cbFirstColor)
				cbSameColor = false;
			if (cbFirstValue != (GetCardLogicValue(cbCardData[i]) + i))
				bLineCard = false;

			// 结束判断
			if ((cbSameColor == false) && (bLineCard == false))
				break;
		}

		// 最小同花顺
		if ((bLineCard == false) && (cbFirstValue == 14)) {
			int i = 1;
			for (i = 1; i < cbCardCount; i++) {
				int cbLogicValue = GetCardLogicValue(cbCardData[i]);
				if ((cbFirstValue != (cbLogicValue + i + 8)))
					break;
			}
			if (i == cbCardCount)
				bLineCard = true;
		}

		// 皇家同花顺
		if ((cbSameColor == true) && (bLineCard == true) && (GetCardLogicValue(cbCardData[1]) == 13))
			return Constants.CT_KING_TONG_HUA_SHUN;

		// 顺子类型
		if ((cbSameColor == false) && (bLineCard == true))
		{
			return Constants.CT_SHUN_ZI;
		}

		// 同花类型
		if ((cbSameColor == true) && (bLineCard == false))
		{
			return Constants.CT_TONG_HUA;
		}

		// 同花顺类型
		if ((cbSameColor == true) && (bLineCard == true))
			return Constants.CT_TONG_HUA_SHUN;

		// 扑克分析
		tagAnalyseResult AnalyseResult = new tagAnalyseResult();
		AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);

		// 类型判断
		if (AnalyseResult.cbFourCount == 1)
			return Constants.CT_TIE_ZHI;
		if (AnalyseResult.cbLONGCount == 2)
			return Constants.CT_TWO_LONG;
		if ((AnalyseResult.cbLONGCount == 1) && (AnalyseResult.cbThreeCount == 1))
			return Constants.CT_HU_LU;
		if ((AnalyseResult.cbThreeCount == 1) && (AnalyseResult.cbLONGCount == 0))
			return Constants.CT_THREE_TIAO;
		if ((AnalyseResult.cbLONGCount == 1) && (AnalyseResult.cbSignedCount == (3-cntZero)))
			return Constants.CT_ONE_LONG;

		return Constants.CT_SINGLE;
	}
	
	public void CopyMemory(int[] by,int[] by2,int length){
		for(int i = 0; i< length;i++){
			by[i] = by2[i];
		}
	}
	
	int getMaPai(int cbCardData[], int cbCardCount,int mapai){
		
		for(int i=0;i<cbCardCount;i++){
			if(cbCardData[i] == mapai){
				return 1;
			}
		}
		return 0;
	}
	
	int GetCardType3Num(int cbCardData[], int cbCardCount) {
		// 数据校验

		int cntZero = 0;
		for(int i=0;i<cbCardCount;i++)
		{
			if(cbCardData[i] == 0)
			{
				cntZero++;
			}
		}
		// 变量定义
		boolean cbSameColor = true, bLineCard = true;
		int cbFirstColor = GetCardColor(cbCardData[0]);
		int cbFirstValue = GetCardLogicValue(cbCardData[0]);

		// 牌形分析
		for (int i = 1; i < cbCardCount; i++) {
			// 数据分析
			if (GetCardColor(cbCardData[i]) != cbFirstColor)
				cbSameColor = false;
			if (cbFirstValue != (GetCardLogicValue(cbCardData[i]) + i))
				bLineCard = false;

			// 结束判断
			if ((cbSameColor == false) && (bLineCard == false))
				break;
		}

		// 最小同花顺
		if ((bLineCard == false) && (cbFirstValue == 14)) {
			int i = 1;
			for (i = 1; i < cbCardCount; i++) {
				int cbLogicValue = GetCardLogicValue(cbCardData[i]);
				if ((cbFirstValue != (cbLogicValue + i + 10)))
					break;
			}
			if (i == cbCardCount)
				bLineCard = true;
		}

		// 皇家同花顺
		if ((cbSameColor == true) && (bLineCard == true) && (GetCardLogicValue(cbCardData[1]) == 13))
			return Constants.CT_KING_TONG_HUA_SHUN;

		// 顺子类型
		if ((cbSameColor == false) && (bLineCard == true))
		{
			return Constants.CT_SHUN_ZI;
		}

		// 同花类型
		if ((cbSameColor == true) && (bLineCard == false))
		{
			return Constants.CT_TONG_HUA;
		}

		// 同花顺类型
		if ((cbSameColor == true) && (bLineCard == true))
			return Constants.CT_TONG_HUA_SHUN;

		// 扑克分析
		tagAnalyseResult AnalyseResult = new tagAnalyseResult();
		AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);

		// 类型判断
		if (AnalyseResult.cbFourCount == 1)
			return Constants.CT_TIE_ZHI;
		if (AnalyseResult.cbLONGCount == 2)
			return Constants.CT_TWO_LONG;
		if ((AnalyseResult.cbLONGCount == 1) && (AnalyseResult.cbThreeCount == 1))
			return Constants.CT_HU_LU;
		if ((AnalyseResult.cbThreeCount == 1) && (AnalyseResult.cbLONGCount == 0))
			return Constants.CT_THREE_TIAO;
		if ((AnalyseResult.cbLONGCount == 1) && (AnalyseResult.cbSignedCount == (3-cntZero)))
			return Constants.CT_ONE_LONG;

		return Constants.CT_SINGLE;
	}
	
	int getHandCardType(int cbCardData[], int cbCardCount){
		
		
		SortCardList(cbCardData,cbCardCount);
		// 变量定义
		boolean cbSameColor = true, bLineCard = true;
		int cbFirstColor = GetCardColor(cbCardData[0]);
		int cbFirstValue = GetCardLogicValue(cbCardData[0]);

		// 牌形分析
		for (int i = 1; i < cbCardCount; i++) {
			// 数据分析
			if (GetCardColor(cbCardData[i]) != cbFirstColor)
				cbSameColor = false;
			if (cbFirstValue != (GetCardLogicValue(cbCardData[i]) + i))
				bLineCard = false;

			// 结束判断
			if ((cbSameColor == false) && (bLineCard == false))
				break;
		}

		// 至尊青龙
		if ((cbSameColor == true) && (bLineCard == true)&&(GetCardLogicValue(cbCardData[0]) == 14))
		{
			return Constants.CT_ZHIZUNQINGLONG;
		}

		// 一条龙
		if ((cbSameColor == false) && (bLineCard == true)&&(GetCardLogicValue(cbCardData[0]) == 14))
		{
			return Constants.CT_YITIAOLONG;
		}
		
		// 扑克分析
		tagAnalyseResult13 AnalyseResult = new tagAnalyseResult13();
		AnalysebCardData13(cbCardData, cbCardCount, AnalyseResult);

		// 类型判断

		if (AnalyseResult.cbThreeCount == 4)//四套三条
			return Constants.CT_SITAOSANTIAO;
		if ((AnalyseResult.cbLONGCount == 6)||(AnalyseResult.cbLONGCount == 5&&AnalyseResult.cbThreeCount == 1)||(AnalyseResult.cbLONGCount == 4&&AnalyseResult.cbFourCount == 1)||(AnalyseResult.cbLONGCount == 2&&AnalyseResult.cbFourCount == 2)||(AnalyseResult.cbFourCount == 3))//六对半
			return Constants.CT_LIUDUIBAN;
		
		return 0;
	}

	// 获取类型
		int GetCardTypeZJ(int cbCardData[], int cbCardCount) {
			
			// 变量定义
			boolean cbSameColor = true, bLineCard = true;
			int cbFirstColor = GetCardColor(cbCardData[0]);
			int cbFirstValue = GetCardLogicValue(cbCardData[0]);

			// 牌形分析
			for (int i = 1; i < cbCardCount; i++) {
				// 数据分析
				if (GetCardColor(cbCardData[i]) != cbFirstColor)
					cbSameColor = false;
				if (cbFirstValue != (GetCardLogicValue(cbCardData[i]) + i))
					bLineCard = false;

				// 结束判断
				if ((cbSameColor == false) && (bLineCard == false))
					break;
			}

			// 最小同花顺
			if ((bLineCard == false) && (cbFirstValue == 14)) {
				int i = 1;
				for (i = 1; i < cbCardCount; i++) {
					int cbLogicValue = GetCardLogicValue(cbCardData[i]);
					if ((cbFirstValue != (cbLogicValue + i + 8)))
						break;
				}
				if (i == cbCardCount)
					bLineCard = true;
			}

			// 皇家同花顺
			if ((cbSameColor == true) && (bLineCard == true) && (GetCardLogicValue(cbCardData[1]) == 13))
				return Constants.CT_KING_TONG_HUA_SHUN;

			// 顺子类型
			if ((cbSameColor == false) && (bLineCard == true))
				return Constants.CT_SHUN_ZI;

			// 同花类型
			if ((cbSameColor == true) && (bLineCard == false))
				return Constants.CT_TONG_HUA;

			// 同花顺类型
			if ((cbSameColor == true) && (bLineCard == true))
				return Constants.CT_TONG_HUA_SHUN;

			// 扑克分析
			tagAnalyseResult AnalyseResult = new tagAnalyseResult();
			AnalysebCardData(cbCardData, cbCardCount, AnalyseResult);

			// 类型判断
			if (AnalyseResult.cbFourCount == 1)
				return Constants.CT_TIE_ZHI;
			if (AnalyseResult.cbLONGCount == 2)
				return Constants.CT_TWO_LONG;
			if ((AnalyseResult.cbLONGCount == 1) && (AnalyseResult.cbThreeCount == 1))
				return Constants.CT_HU_LU;
			if ((AnalyseResult.cbThreeCount == 1) && (AnalyseResult.cbLONGCount == 0))
				return Constants.CT_THREE_TIAO;
			if ((AnalyseResult.cbLONGCount == 1) && (AnalyseResult.cbSignedCount == 3))
				return Constants.CT_ONE_LONG;

			return Constants.CT_SINGLE;
		}
	// 排列扑克
	void SortCardList(int cbCardData[], int cbCardCount) {
		// 转换数值
		int cbLogicValue[] = new int[65];
		for (int i = 0; i < cbCardCount; i++)
			cbLogicValue[i] = GetCardLogicValue(cbCardData[i]);

		// 排序操作
		boolean bSorted = true;
		int cbTempData, bLast = cbCardCount - 1;
		do {
			bSorted = true;
			for (int i = 0; i < bLast; i++) {
				if ((cbLogicValue[i] < cbLogicValue[i + 1])
						|| ((cbLogicValue[i] == cbLogicValue[i + 1]) && (cbCardData[i] < cbCardData[i + 1]))) {
					// 交换位置
					cbTempData = cbCardData[i];
					cbCardData[i] = cbCardData[i + 1];
					cbCardData[i + 1] = cbTempData;
					cbTempData = cbLogicValue[i];
					cbLogicValue[i] = cbLogicValue[i + 1];
					cbLogicValue[i + 1] = cbTempData;
					bSorted = false;
				}
			}
			bLast--;
		} while (bSorted == false);

		return;
	}
	
	// 排列扑克
	void SortCardListBeginSmall(int cbCardData[], int cbCardCount) {
		// 转换数值
		int cbLogicValue[] = new int[65];
		for (int i = 0; i < cbCardCount; i++)
			cbLogicValue[i] = GetCardLogicValueBeginSmall(cbCardData[i]);

		// 排序操作
		boolean bSorted = true;
		int cbTempData, bLast = cbCardCount - 1;
		do {
			bSorted = true;
			for (int i = 0; i < bLast; i++) {
				if ((cbLogicValue[i] > cbLogicValue[i + 1])
						|| ((cbLogicValue[i] == cbLogicValue[i + 1]) && (cbCardData[i] > cbCardData[i + 1]))) {
					// 交换位置
					cbTempData = cbCardData[i];
					cbCardData[i] = cbCardData[i + 1];
					cbCardData[i+1] = cbTempData;
					cbTempData = cbLogicValue[i];
					cbLogicValue[i] = cbLogicValue[i + 1];
					cbLogicValue[i+1] = cbTempData;
					bSorted = false;
				}
			}
			bLast--;
		} while (bSorted == false);

		return;
	}
public void getCardType(int[] cardData,int[] typeArray,int[][] cardTypeList){
		
		
		SortSmallCardList(cardData,cardData.length);
		///////////////////////////////////////同花顺////////////////////////////////////
		 for(int j=0;j<cardData.length-4;j++)
         {
			
            	 //顺子
            	 if(cardData[j] == cardData[j+1]+1
	                &&cardData[j] == cardData[j+2]+2
	            	&&cardData[j] == cardData[j+3]+3
	            	&&cardData[j] ==cardData[j+4]+4)
            	 {
            		 
            		 
            		 
            		 //同花
                     if(GetCardColor(cardData[j]) == GetCardColor(cardData[j+1])
        		            		 &&GetCardColor(cardData[j]) == GetCardColor(cardData[j+2])
        		            		 &&GetCardColor(cardData[j]) == GetCardColor(cardData[j+3])
        		            		 &&GetCardColor(cardData[j]) == GetCardColor(cardData[j+4]))
                     {
                    	 
                 		//同花顺
                 		for(int c=0;c<5;c++)
                 		{
                 			 cardTypeList[0][c] = cardData[j+c];
                 		}
                 		typeArray[0] = 1;
                 		 break;
                     }
            		 
            	
            	 }
                
             
         }
		 
		 //////////////////////////////////铁支//////////////////
		 
		 for(int j=0;j<cardData.length-3;j++)
         {
			 
        	 if(cardData[j]%16 == cardData[j+1]%16
                &&cardData[j]%16 == cardData[j+2]%16
            	&&cardData[j]%16 == cardData[j+3]%16)
        	 {
        		
        		for(int c=0;c<4;c++){
        			 cardTypeList[1][c] = cardData[j+c];
        		}
        		
        		 for(int k=0;k<cardData.length;k++)
                 {
        			
        			 if(cardData[k]%16 != cardData[j]%16){
        				 cardTypeList[1][4] = cardData[k];
        			 }
                 }
        		 typeArray[1] = 1;
        		 break;
        		
        	 }
         }
		 
         //////////////////////////////////葫芦//////////////////
		 
		 for(int j=0;j<cardData.length-2;j++)
         {
			 
        	 if(cardData[j]%16 == cardData[j+1]%16
                &&cardData[j]%16 == cardData[j+2]%16)
        	 {
        		
        		 for(int k=0;k<cardData.length-1;k++)
                 {
        			                 
        			 if(cardData[k]%16 == cardData[k+1]%16&&cardData[k]%16 != cardData[j]%16){
        				 cardTypeList[2][0] = cardData[j];
        				 cardTypeList[2][1] = cardData[j+1];
        				 cardTypeList[2][2] = cardData[j+2];
        				 cardTypeList[2][3] = cardData[k];
        				 cardTypeList[2][4] = cardData[k+1];
        				 typeArray[2] = 1;
        				 break;
        			 }
                 }
        		
        	 }
         }
         //////////////////////////////////同花//////////////////
		 int[] fang = new int[26];int[] mei = new int[26];int[] hong = new int[26];int[] hei = new int[26];
		 int fangNum = 0;int meiNum = 0;int hongNum = 0; int heiNum = 0;  
		 for(int j=0;j<cardData.length;j++)
         {
			 int color = (int) Math.floor(cardData[j]/16);
			
			 if(color == 0)
			 {
				 fangNum++;
				 fang[fangNum-1] = cardData[j];
				 if(fangNum>=5){
						
		         		for(int c=0;c<5;c++)
		         		{
		         			 cardTypeList[3][c] = fang[c];
		         		}
		         		typeArray[3] = 1;
				 }
			 }
			 if(color == 1)
			 {
				 meiNum++;
				 mei[meiNum-1] = cardData[j];
				 if(meiNum>=5){
						
		         		for(int c=0;c<5;c++)
		         		{
		         			 cardTypeList[3][c] = mei[c];
		         		}
		         		typeArray[3] = 1;
				 }
			 }
			 if(color == 2)
			 {
				 hongNum++;
				 hong[hongNum-1] = cardData[j];
				 if(hongNum>=5){
						
		         		for(int c=0;c<5;c++)
		         		{
		         			 cardTypeList[3][c] = hong[c];
		         		}
		         		typeArray[3] = 1;
				 }
			 }
			 if(color == 3)
			 {
				 heiNum++;
				 hei[heiNum-1] = cardData[j];
				 if(heiNum>=5){
					
		         		for(int c=0;c<5;c++)
		         		{
		         			 cardTypeList[3][c] = hei[c];
		         		}
		         		typeArray[3] = 1;
				 }
			 }
			 
			
         }
		 
		 
			///////////////////////////////////////顺子////////////////////////////////////
		 ArrayList<Integer> tempList = new ArrayList<Integer>();
		 for(int j=0;j<cardData.length-4;j++)
         {
			 if(!tempList.contains(cardData[j]))
			 {
				 tempList.add(cardData[j]);
	            
			 } 
         }
		 
		 
		 for(int j=0;j<tempList.size()-4;j++)
         {
			//顺子
        	 if(cardData[j]%16 == cardData[j+1]%16+1
                &&cardData[j]%16 == cardData[j+2]%16+2
            	&&cardData[j]%16 == cardData[j+3]%16+3
            	&&cardData[j]%16 ==cardData[j+4]%16+4)
        	 {
        		//同花顺
        		for(int c=0;c<5;c++){
        			 cardTypeList[4][c] = cardData[j+c];
        		}
        		typeArray[4] = 1;
        		break;
        	 }
         }
		 
		 
           //////////////////////////////////三条//////////////////
		 
		 for(int j=0;j<cardData.length-2;j++)
         {
			 
        	 if(cardData[j]%16 == cardData[j+1]%16
                &&cardData[j]%16 == cardData[j+2]%16)
        	 {
        		 int count = 0;
        		 int[] countNum = new int[2];
        		 for(int k=0;k<cardData.length-1;k++)
                 {
        			 
        			 if(cardData[k]%16 != cardData[j]%16){
        				 count++;
        				 countNum[count-1] = cardData[k];
        				 if(count == 2){
        					 cardTypeList[5][0] = cardData[j];
            				 cardTypeList[5][1] = cardData[j+1];
            				 cardTypeList[5][2] = cardData[j+2];
            				 cardTypeList[5][3] = countNum[0];
            				 cardTypeList[5][4] = countNum[1];
            				 typeArray[5] = 1;
            				 break;
        				 }
        				
        			 }
                 }
        		
        	 }
         }
		 
       //////////////////////////////////两对//////////////////
		 
		 for(int j=0;j<cardData.length-1;j++)
         {
			 
        	 if(cardData[j]%16 == cardData[j+1]%16)
        	 {
        		 int[] tempData = new int[cardData.length-2];
        		 int index = 0;
        		 for(int k=0;k<cardData.length;k++)
                 {
        			 
                	 if(cardData[k] != cardData[j]&&cardData[k] != cardData[j+1])
                	 {
                		 index++;
                		 tempData[index-1] = cardData[k];
                	 }
                	 
                 }
        		 
        		 for(int k=0;k<tempData.length-1;k++)
                 {
        			 
                	 if(tempData[k]%16 == tempData[k+1]%16)
                	 {
                		
                		 
                		 for(int m=0;m<cardData.length;m++)
                         {
                			
                        	 if(cardData[m]%16 != cardData[j]%16
                                &&cardData[m]%16 != cardData[j+1]%16
                            	&&cardData[m]%16 != tempData[k]%16
                            	&&cardData[m]%16 != tempData[k+1]%16)
                        	 {
                        		 cardTypeList[5][0] = cardData[j];
                				 cardTypeList[5][1] = cardData[j+1];
                				 cardTypeList[5][2] = tempData[k];
                				 cardTypeList[5][3] = tempData[k+1];
                				 cardTypeList[5][4] = cardData[m];
                				 typeArray[5] = 1;
                				 break;
                        	 }
                         }
                		 
                		
                	 }
                	 
                 }
        		
        	 }
         }
		 
		 
		 
  //////////////////////////////////对子//////////////////
		 
		 for(int j=0;j<cardData.length-1;j++)
         {
			 //一对
        	 if(cardData[j]%16 == cardData[j+1]%16)
        	 {
        		
        		 for(int k=0;k<cardData.length;k++)
                 {
        			 //第一个
                	 if(cardData[k]%16 != cardData[j]%16)
                	 {
                		
                		 for(int m=0;m<cardData.length;m++)
                         {
                			//第二个
                        	 if(cardData[m]%16 != cardData[j]%16&&cardData[m]%16 != cardData[k]%16)
                        	 {
                        		 for(int t=0;t<cardData.length;t++)
                                 {
                        			//第三个
                                	 if(cardData[t]%16 != cardData[j]%16&&cardData[t]%16 != cardData[k]%16&&cardData[t]%16 != cardData[m]%16)
                                	 {
                                		 cardTypeList[6][0] = cardData[j];
                        				 cardTypeList[6][1] = cardData[j+1];
                        				 cardTypeList[6][2] = cardData[k];
                        				 cardTypeList[6][3] = cardData[m];
                        				 cardTypeList[6][4] = cardData[t];
                        				 typeArray[6] = 1;
                        				 break;
                                		
                                	 }
                                 }
                        		
                        	 }
                         }
                	 }
                 }
        	 }
         }
		 
		
	}
//排列扑克
	void SortSmallCardList(int cbCardData[], int cbCardCount) {
		// 转换数值
		int cbLogicValue[] = new int[52];
		for (int i = 0; i < cbCardCount; i++)
			cbLogicValue[i] = GetCardLogicValue(cbCardData[i]);

		// 排序操作
		boolean bSorted = true;
		int cbTempData, bLast = cbCardCount - 1;
		do {
			bSorted = true;
			for (int i = 0; i < bLast; i++) {
				if ((cbLogicValue[i] >cbLogicValue[i + 1])
						|| ((cbLogicValue[i] == cbLogicValue[i + 1]) && (cbCardData[i] > cbCardData[i + 1]))) {
					// 交换位置
					cbTempData = cbCardData[i];
					cbCardData[i] = cbCardData[i+1];
					cbCardData[i+1] = cbTempData;
					cbTempData = cbLogicValue[i];
					cbLogicValue[i] = cbLogicValue[i+1];
					cbLogicValue[i+1] = cbTempData;
					bSorted = false;
				}
				
			}
			bLast--;
		} while (bSorted == false);

		return;
	}
	int CompareThreeCard(int cbFirstData[], int cbNextData[], int cbCardCount){
		
		SortCardList(cbFirstData,cbCardCount);
		SortCardList(cbNextData,cbCardCount);
		// 获取类型
		int cbNextType = GetCardType(cbNextData, 5);
		int cbFirstType = GetCardType(cbFirstData, 5);

		// 类型判断
		// 大
		if (cbFirstType > cbNextType)
			return 2;

		// 小
		if (cbFirstType < cbNextType)
			return 1;
		
		// 是否三个相等
		int firstZeroNum = 0;
		int nextZeroNum = 0;
		for(int i=0;i<2;i++){
			int cbNextValue1 = GetCardLogicValue(cbNextData[i]);
			int cbNextValue2 = GetCardLogicValue(cbNextData[i+1]);
			
			int cbFirstValue1 = GetCardLogicValue(cbFirstData[i]);
			int cbFirstValue2= GetCardLogicValue(cbFirstData[i+1]);

			if(cbNextValue1 - cbNextValue2==0){
				nextZeroNum++;
			}
			if(cbFirstValue1 - cbFirstValue2 ==0){
				firstZeroNum++;
			}
			
		}
		
		
		
		if(firstZeroNum ==2&&nextZeroNum!=2){
			return 2;
		}
		if(firstZeroNum !=2&&nextZeroNum==2){
			return 1;
		}
		if(firstZeroNum !=2&&nextZeroNum!=2){
			
			if(firstZeroNum ==1&&nextZeroNum!=1){
				return 2;
			}
			if(firstZeroNum !=1&&nextZeroNum==1){
				return 1;
			}
			if(firstZeroNum !=1&&nextZeroNum!=1){
				
				for(int i=0;i<cbCardCount;i++){
					int numFirst = GetCardLogicValue(cbFirstData[i]);
					int numNext = GetCardLogicValue(cbNextData[i]);
					if(numFirst>numNext){
						return 2;
					}
					if(numFirst<numNext){
						return 1;
					}
				}
				for(int i=0;i<cbCardCount;i++){
					int numFirst = GetCardLogicValue(cbFirstData[i]);
					int numNext = GetCardLogicValue(cbNextData[i]);
					if(numFirst==numNext){
						// 黑桃》红心》梅花》方块
						//牌型花色：方  梅  红  黑
						int colorFirst = (int) Math.floor(cbFirstData[i]/16);
						int colorNext = (int) Math.floor(cbNextData[i]/16);
					
						if(colorFirst>colorNext){
							return 1;
						}
						if(colorFirst<colorNext){
							return 2;
						}
						if(colorFirst==colorNext){
							break;
						}
						
						
					}
				}
				
			}
			
		}
		return 0;
		
	}

	// 对比扑克
	int CompareCard(int cbFirstData[], int cbNextData[], int cbCardCount) {
		// 获取类型
		
		int cbFirstType = GetCardType(cbFirstData, cbCardCount);
		int cbNextType = GetCardType(cbNextData, cbCardCount);

		// 类型判断
		// 大
		if (cbFirstType > cbNextType)
			return 2;

		// 小
		if (cbFirstType < cbNextType)
			return 1;

		// 简单类型
		switch (cbFirstType) {
		case Constants.CT_SINGLE: // 单牌
		{
			// 对比数值
			int i = 0;
			for (i = 0; i < cbCardCount; i++) {
				int cbNextValue = GetCardLogicValue(cbNextData[i]);
				int cbFirstValue = GetCardLogicValue(cbFirstData[i]);

				// 大
				if (cbFirstValue > cbNextValue)
					return 2;
				// 小
				else if (cbFirstValue < cbNextValue)
					return 1;
				// 等
				else
					continue;
			}
			// 平
			if (i == cbCardCount) {
				i = 0;
				for (i = 0; i < cbCardCount; i++) {

					int cbFirstColor = GetCardColor(cbFirstData[i]);
					int cbNextColor = GetCardColor(cbNextData[i]);

					// 大
					if (cbFirstColor > cbNextColor)
						return 2;
					// 小
					else if (cbFirstColor < cbNextColor)
						return 1;
					// 等
					else
						continue;
				}
				return 0;
			}
			break;
		}
		case Constants.CT_ONE_LONG: // 对子
		case Constants.CT_TWO_LONG: // 两对
		case Constants.CT_THREE_TIAO: // 三条
		case Constants.CT_TIE_ZHI: // 铁支
		case Constants.CT_HU_LU: // 葫芦
		{
			// 分析扑克
			tagAnalyseResult AnalyseResultNext = new tagAnalyseResult();
			tagAnalyseResult AnalyseResultFirst = new tagAnalyseResult();
			AnalysebCardData(cbNextData, cbCardCount, AnalyseResultNext);
			AnalysebCardData(cbFirstData, cbCardCount, AnalyseResultFirst);

			// 四条数值
			if (AnalyseResultFirst.cbFourCount > 0) {
				int cbNextValue = AnalyseResultNext.cbFourLogicVolue[0];
				int cbFirstValue = AnalyseResultFirst.cbFourLogicVolue[0];

				// 比较四条
				if (cbFirstValue != cbNextValue)
					return (cbFirstValue > cbNextValue) ? 2 : 1;

				// 比较单牌
				cbFirstValue = AnalyseResultFirst.cbSignedLogicVolue[0];
				cbNextValue = AnalyseResultNext.cbSignedLogicVolue[0];
				if (cbFirstValue != cbNextValue)
					return (cbFirstValue > cbNextValue) ? 2 : 1;
				else {
					int i = 0;
					for (i = 0; i < cbCardCount; i++) {

						int cbFirstColor = GetCardColor(cbFirstData[i]);
						int cbNextColor = GetCardColor(cbNextData[i]);

						// 大
						if (cbFirstColor > cbNextColor)
							return 2;
						// 小
						else if (cbFirstColor < cbNextColor)
							return 1;
						// 等
						else
							continue;
					}
					return 0;
				}
			}

			// 三条数值
			if (AnalyseResultFirst.cbThreeCount > 0) {
				int cbNextValue = AnalyseResultNext.cbThreeLogicVolue[0];
				int cbFirstValue = AnalyseResultFirst.cbThreeLogicVolue[0];

				// 比较三条
				if (cbFirstValue != cbNextValue)
					return (cbFirstValue > cbNextValue) ? 2 : 1;

				// 葫芦牌型
				if (Constants.CT_HU_LU == cbFirstType) {
					// 比较对牌
					cbFirstValue = AnalyseResultFirst.cbLONGLogicVolue[0];
					cbNextValue = AnalyseResultNext.cbLONGLogicVolue[0];
					if (cbFirstValue != cbNextValue)
						return (cbFirstValue > cbNextValue) ? 2 : 1;
					else{
						int i = 0;
						for (i = 0; i < cbCardCount; i++) {

							int cbFirstColor = GetCardColor(cbFirstData[i]);
							int cbNextColor = GetCardColor(cbNextData[i]);

							// 大
							if (cbFirstColor > cbNextColor)
								return 2;
							// 小
							else if (cbFirstColor < cbNextColor)
								return 1;
							// 等
							else
								continue;
						}
						return 0;
					}
				} else // 三条带单
				{
					// 比较单牌

					// 散牌数值
					int i = 0;
					for (i = 0; i < AnalyseResultFirst.cbSignedCount; i++) {
						int cbNextValue2 = AnalyseResultNext.cbSignedLogicVolue[i];
						int cbFirstValue2 = AnalyseResultFirst.cbSignedLogicVolue[i];
						// 大
						if (cbFirstValue > cbNextValue2)
							return 2;
						// 小
						else if (cbFirstValue2 < cbNextValue2)
							return 1;
						// 等
						else
							continue;
					}
					if (i == AnalyseResultFirst.cbSignedCount)
					{
						i = 0;
						for (i = 0; i < cbCardCount; i++) {

							int cbFirstColor = GetCardColor(cbFirstData[i]);
							int cbNextColor = GetCardColor(cbNextData[i]);

							// 大
							if (cbFirstColor > cbNextColor)
								return 2;
							// 小
							else if (cbFirstColor < cbNextColor)
								return 1;
							// 等
							else
								continue;
						}
						return 0;
					}
				}
			}

			// 对子数值
			int i = 0;
			for (i = 0; i < AnalyseResultFirst.cbLONGCount; i++) {
				int cbNextValue = AnalyseResultNext.cbLONGLogicVolue[i];
				int cbFirstValue = AnalyseResultFirst.cbLONGLogicVolue[i];
				// 大
				if (cbFirstValue > cbNextValue)
					return 2;
				// 小
				else if (cbFirstValue < cbNextValue)
					return 1;
				// 平
				else
					continue;
			}

			// 比较单牌
			{

				// 散牌数值
				for (i = 0; i < AnalyseResultFirst.cbSignedCount; i++) {
					int cbNextValue = AnalyseResultNext.cbSignedLogicVolue[i];
					int cbFirstValue = AnalyseResultFirst.cbSignedLogicVolue[i];
					// 大
					if (cbFirstValue > cbNextValue)
						return 2;
					// 小
					else if (cbFirstValue < cbNextValue)
						return 1;
					// 等
					else
						continue;
				}
				// 平
				if (i == AnalyseResultFirst.cbSignedCount)
				{
					i = 0;
					for (i = 0; i < cbCardCount; i++) {

						int cbFirstColor = GetCardColor(cbFirstData[i]);
						int cbNextColor = GetCardColor(cbNextData[i]);

						// 大
						if (cbFirstColor > cbNextColor)
							return 2;
						// 小
						else if (cbFirstColor < cbNextColor)
							return 1;
						// 等
						else
							continue;
					}
					return 0;
				}
			}
			break;
		}
		case Constants.CT_SHUN_ZI: // 顺子
		case Constants.CT_TONG_HUA_SHUN: // 同花顺
		case Constants.CT_KING_TONG_HUA_SHUN: // 同花顺
		{
			// 数值判断
			int cbNextValue = GetCardLogicValue(cbNextData[0]);
			int cbFirstValue = GetCardLogicValue(cbFirstData[0]);

			boolean bFirstmin = (cbFirstValue == (GetCardLogicValue(cbFirstData[1]) + 9));
			boolean bNextmin = (cbNextValue == (GetCardLogicValue(cbNextData[1]) + 9));

/*
			// 大小顺子
			if ((cbFirstValue == 14) && (bFirstmin == true) && (bNextmin == false)) {
				return 1;
			}
			// 大小顺子
			else if ((cbNextValue == 14) && (bFirstmin == false) && (bNextmin == true)) {
				return 2;
			}
*/
			if(cbFirstValue > cbNextValue)
			{
				return 2;
			}else if(cbFirstValue < cbNextValue)
			{
				return 1;
			}else {
				// 平
				if (cbFirstValue == cbNextValue)
				{
					if ((cbFirstValue == 14) && (bFirstmin == true) && (bNextmin == false)) {
						return 1;
					}
					if ((cbNextValue == 14) && (bFirstmin == false) && (bNextmin == true)) {
						return 2;
					}
					int i = 0;
					for (i = 0; i < cbCardCount; i++) {

						int cbFirstColor = GetCardColor(cbFirstData[i]);
						int cbNextColor = GetCardColor(cbNextData[i]);

						// 大
						if (cbFirstColor > cbNextColor)
							return 2;
						// 小
						else if (cbFirstColor < cbNextColor)
							return 1;
						// 等
						else
							continue;
					}
					return 0;
				}
				return (cbFirstValue > cbNextValue) ? 2 : 1;
			}
		}
		case Constants.CT_TONG_HUA: // 同花
		{
			int i = 0;
			// 散牌数值
			for (i = 0; i < cbCardCount; i++) {
				int cbNextValue = GetCardLogicValue(cbNextData[i]);
				int cbFirstValue = GetCardLogicValue(cbFirstData[i]);

				if (cbFirstValue == cbNextValue)
					continue;
				return (cbFirstValue > cbNextValue) ? 2 : 1;
			}
			// 平
			if (i == cbCardCount)
			{
				i = 0;
				for (i = 0; i < cbCardCount; i++) {

					int cbFirstColor = GetCardColor(cbFirstData[i]);
					int cbNextColor = GetCardColor(cbNextData[i]);

					// 大
					if (cbFirstColor > cbNextColor)
						return 2;
					// 小
					else if (cbFirstColor < cbNextColor)
						return 1;
					// 等
					else
						continue;
				}
				return 0;
			}
		}
		}

		return 0;
	}

	// 分析扑克
	public void AnalysebCardData(int cbCardData[], int cbCardCount, tagAnalyseResult AnalyseResult) {
		// 设置结果
		AnalyseResult.clear();

		// 扑克分析
		for (int i = 0; i < cbCardCount; i++) {
			// 变量定义
			
			int cbSameCardData[] = { cbCardData[i], 0, 0, 0, 0 };
			int cbLogicValue = GetCardLogicValue(cbCardData[i]);

			if(cbLogicValue != 0)
			{
				int cbSameCount = 1;
				// 获取同牌
				for (int j = i + 1; j < cbCardCount; j++) {
					// 逻辑对比
					if (GetCardLogicValue(cbCardData[j]) != cbLogicValue) {
						break;
					}
					if(cbCardData[j] != 0)
					{
						// 设置扑克
						cbSameCardData[cbSameCount++] = cbCardData[j];					
					}
				}
			


			// 保存结果
			switch (cbSameCount) {
			case 1: // 单张
			{
				AnalyseResult.cbSignedLogicVolue[AnalyseResult.cbSignedCount] = cbLogicValue;
				for (int k = 0; k < cbSameCount; k++) {
					AnalyseResult.cbSignedCardData[(AnalyseResult.cbSignedCount) * cbSameCount + k] = cbSameCardData[k];
				}
				AnalyseResult.cbSignedCount++;
				break;
			}
			case 2: // 两张
			{
				AnalyseResult.cbLONGLogicVolue[AnalyseResult.cbLONGCount] = cbLogicValue;
				for (int k = 0; k < cbSameCount; k++) {
					AnalyseResult.cbLONGCardData[(AnalyseResult.cbLONGCount) * cbSameCount + k] = cbSameCardData[k];
				}
				AnalyseResult.cbLONGCount++;
				break;
			}
			case 3: // 三张
			{
				AnalyseResult.cbThreeLogicVolue[AnalyseResult.cbThreeCount] = cbLogicValue;
				for (int k = 0; k < cbSameCount; k++) {
					AnalyseResult.cbThreeCardData[(AnalyseResult.cbThreeCount) * cbSameCount + k] = cbSameCardData[k];
				}
				AnalyseResult.cbThreeCount++;
				break;
			}
			case 4: // 四张
			{
				AnalyseResult.cbFourLogicVolue[AnalyseResult.cbFourCount] = cbLogicValue;
				for (int k = 0; k < cbSameCount; k++) {
					AnalyseResult.cbFourCardData[(AnalyseResult.cbFourCount) * cbSameCount + k] = cbSameCardData[k];
				}
				AnalyseResult.cbFourCount++;
				break;
			}
			case 5: // 五张
			{
				AnalyseResult.cbFiveLogicVolue[AnalyseResult.cbFiveCount] = cbLogicValue;
				for (int k = 0; k < cbSameCount; k++) {
					AnalyseResult.cbFiveCardData[(AnalyseResult.cbFiveCount) * cbSameCount + k] = cbSameCardData[k];
				}
				AnalyseResult.cbFiveCount++;
				break;
			}
			}

			// 设置递增
			i += cbSameCount - 1;
			}

		}

		return;
	}
	
	// 分析扑克
		public void AnalysebCardData13(int cbCardData[], int cbCardCount, tagAnalyseResult13 AnalyseResult) {
			// 设置结果
			AnalyseResult.clear();

			// 扑克分析
			for (int i = 0; i < cbCardCount; i++) {
				// 变量定义
				
				int cbSameCardData[] = { cbCardData[i], 0, 0, 0, 0,0,0,0};
				int cbLogicValue = GetCardLogicValue(cbCardData[i]);

				if(cbLogicValue != 0)
				{
					int cbSameCount = 1;
					// 获取同牌
					for (int j = i + 1; j < cbCardCount; j++) {
						// 逻辑对比
						if (GetCardLogicValue(cbCardData[j]) != cbLogicValue) {
							break;
						}
						if(cbCardData[j] != 0)
						{
							// 设置扑克
							cbSameCardData[cbSameCount++] = cbCardData[j];					
						}
					}
				


				// 保存结果
				switch (cbSameCount) {
				case 1: // 单张
				{
					AnalyseResult.cbSignedLogicVolue[AnalyseResult.cbSignedCount] = cbLogicValue;
					for (int k = 0; k < cbSameCount; k++) {
						AnalyseResult.cbSignedCardData[(AnalyseResult.cbSignedCount) * cbSameCount + k] = cbSameCardData[k];
					}
					AnalyseResult.cbSignedCount++;
					break;
				}
				case 2: // 两张
				{
					AnalyseResult.cbLONGLogicVolue[AnalyseResult.cbLONGCount] = cbLogicValue;
					for (int k = 0; k < cbSameCount; k++) {
						AnalyseResult.cbLONGCardData[(AnalyseResult.cbLONGCount) * cbSameCount + k] = cbSameCardData[k];
					}
					AnalyseResult.cbLONGCount++;
					break;
				}
				case 3: // 三张
				{
					AnalyseResult.cbThreeLogicVolue[AnalyseResult.cbThreeCount] = cbLogicValue;
					for (int k = 0; k < cbSameCount; k++) {
						AnalyseResult.cbThreeCardData[(AnalyseResult.cbThreeCount) * cbSameCount + k] = cbSameCardData[k];
					}
					AnalyseResult.cbThreeCount++;
					break;
				}
				case 4: // 四张
				{
					AnalyseResult.cbFourLogicVolue[AnalyseResult.cbFourCount] = cbLogicValue;
					for (int k = 0; k < cbSameCount; k++) {
						AnalyseResult.cbFourCardData[(AnalyseResult.cbFourCount) * cbSameCount + k] = cbSameCardData[k];
					}
					AnalyseResult.cbFourCount++;
					break;
				}
				}

				// 设置递增
				i += cbSameCount - 1;
				}

			}

			return;
		}
	//////////////////////////////////////////////////////////////////////////

}
